<head>
<!-- Copyright (C) 2020 mn

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. 
--> 
<title>quasi 2.1</title>
<style>
div {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
textarea {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
button {height: 30px; font-family: sans; font-weight: bold;}
.letter {height: 30px; padding: 0px; margin: 0px; width: 30px;}
.cap {text-transform: capitalize;}
</style>
</head>

<body>
<span id="progrun">
</span>
<div id="dtop" style="position: absolute; top: 1%; left: 1%; width: 98%; height: 35%;"><br>&nbsp;display window</div>
<textarea id="dleft" style="position: absolute; top: 38%; left: 1%; width: 38%; height: 58%;">

# import window 

func function
    st get 2 
    p ; for 1 st 1
       thisone get -50 prints
       next
    he get "" print
    next

st get 10
p ; for 1 st 1
    thisone get 55
    now = get "hello" func print
    thisone print
    hello = date ; mid 2 1
    now = get "u tc" ; split now " "  
    now = join now "" ; prints 
    m get 45 chr prints
    now ; get hello ; print
    next</textarea>
<div id="dmid" style="position: absolute; top: 38%; left: 41%; width: 58%; height: 58%;"><br>&nbsp;<button class="cap" onclick="javascript:runimport();">run program</button>
<button class="cap" onclick="javascript:showcompiledimport();">show compiled javascript</button>
<button class="cap" onclick="javascript:showhelp();">help</button>
<button class="cap" onclick="javascript:showlicense(licenseinfo);">info</button>
<br><br><center><table><tr><td><center>
<button class="letter" onclick="javascript:cursorletter('q');">q</button>
<button class="letter" onclick="javascript:cursorletter('w');">w</button>
<button class="letter" onclick="javascript:cursorletter('e');">e</button>
<button class="letter" onclick="javascript:cursorletter('r');">r</button>
<button class="letter" onclick="javascript:cursorletter('t');">t</button>
<button class="letter" onclick="javascript:cursorletter('y');">y</button>
<button class="letter" onclick="javascript:cursorletter('u');">u</button>
<button class="letter" onclick="javascript:cursorletter('i');">i</button>
<button class="letter" onclick="javascript:cursorletter('o');">o</button>
<button class="letter" onclick="javascript:cursorletter('p');">p</button>

<br><br>
<button class="letter" onclick="javascript:cursorletter('a');">a</button>
<button class="letter" onclick="javascript:cursorletter('s');">s</button>
<button class="letter" onclick="javascript:cursorletter('d');">d</button>
<button class="letter" onclick="javascript:cursorletter('f');">f</button>
<button class="letter" onclick="javascript:cursorletter('g');">g</button>
<button class="letter" onclick="javascript:cursorletter('h');">h</button>
<button class="letter" onclick="javascript:cursorletter('j');">j</button>
<button class="letter" onclick="javascript:cursorletter('k');">k</button>
<button class="letter" onclick="javascript:cursorletter('l');">l</button>

<br><br>
<button class="letter" onclick="javascript:cursorletter('z');">z</button>
<button class="letter" onclick="javascript:cursorletter('x');">x</button>
<button class="letter" onclick="javascript:cursorletter('c');">c</button>
<button class="letter" onclick="javascript:cursorletter('v');">v</button>
<button class="letter" onclick="javascript:cursorletter('b');">b</button>
<button class="letter" onclick="javascript:cursorletter('n');">n</button>
<button class="letter" onclick="javascript:cursorletter('m');">m</button>
<br><br>
<button style="height: 30px; padding: 0px; width: 270px;" onclick="javascript:cursorletter(' ');"> </button>
</center></td><td><center>
<button class="cap" onclick="javascript:backkey();">bksp</button>
<button class="cap" onclick="javascript:delkey();">del</button>
<br><br>
<button style="height: 30px; padding: 0px; margin: 0px; width: 30px;" onclick="javascript:cursorup();">&#8593;</button>
<br><br>
<button style="height: 30px; padding: 0px; margin: 0px; width: 30px;" onclick="javascript:cursorleft();">&#8592;</button>
<button style="height: 30px; padding: 0px; margin: 0px; width: 30px;" onclick="javascript:cursordown();">&#8595;</button>
<button style="height: 30px; padding: 0px; margin: 0px; width: 30px;" onclick="javascript:cursorright();">&#8594;</button>
<br><br>

<button class="cap" onclick="javascript:enterkey();">enter</button>
<br><br>
<button style="height: 30px; padding: 0px; margin: 0px; width: 40px;" onclick="javascript:cursorskup();">&#8593;&#8593;</button>
<br><br>
<button style="height: 30px; padding: 0px; margin: 0px; width: 40px;" onclick="javascript:cursorskleft();">&#8592;&#8592;</button>
<button style="height: 30px; padding: 0px; margin: 0px; width: 40px;" onclick="javascript:cursorskdown();">&#8595;&#8595;</button>
<button style="height: 30px; padding: 0px; margin: 0px; width: 40px;" onclick="javascript:cursorskright();">&#8594;&#8594;</button>


</center></td></tr></table>
</center>

<br>&nbsp;Homepage: <a href='https://codeinfig.neocities.org/quasi.html'>https://codeinfig.neocities.org/quasi.html</a><br><br>&nbsp;Making of: <a href='https://codeyourownlanguage.neocities.org/quasi.html'>https://codeyourownlanguage.neocities.org/quasi.html</a></div>

<script>dtop.style.background = 'white'; dtop.style.bordercolor = 'black'; dtop.style.border = 'solid';

helptext = "[lit]*[lit] asc - returns unicode value from first character of main variable\
\n[lit]*[lit] chr - returns unicode character of value from main variable\
\n[lit]*[lit] color /-1 to 15! - sets colour to cga 0 - cga 15; -1 is unspecified.\
\n[lit]*[lit] colour /-1 to 15! - sets colour to cga 0 - cga 15; -1 is unspecified.\
\n[lit]*[lit] cls - clears the display window\
\n\
\n[lit]*[lit] cls - clears the display window\
\n[lit]*[lit] date - sets the main variable to the date and time\
\n[lit]*[lit] end - stops the program\
\n[lit]*[lit] for /start! /stop! /step! - creates for loop\
\n[lit]*[lit] function /zero or more parameters! - defines a function\
\n\
\n[lit]*[lit] get /variable! - copies /variable! to the main variable\
\n[lit]*[lit] instr /variable! - finds location of string /variable! in main variable\
\n[lit]*[lit] join /v! /bystring! - join array /v! into string with /bystring! between each item\
\n[lit]*[lit] left /variable! - trims main variable to leftmost /variable! items or characters\
\n[lit]*[lit] len - sets main variable to length of main variable\
\n\
\n[lit]*[lit] mid /p! /length!  - trims main variable from item or character /p! to /length! items or characters\
\n[lit]*[lit] mod /p! - returns main variable modulus /p!\
\n[lit]*[lit] next - marks the end of a loop\
\n[lit]*[lit] print - prints the value of the main variable\
\n[lit]*[lit] prints - prints the value of the main variable and stays on the same line\
\n\
\n[lit]*[lit] return /v! - exits function while setting main variable to /v!\
\n[lit]*[lit] right /variable! - trims main variable to rightmost /variable! items or characters\
\n[lit]*[lit] split /v! /bystring! - converts string /v! to array, split by /bystring!\
\n[lit]*[lit] str - returns the value of the main variable as a string\
\n[lit]*[lit] title - sets the page title to the value of the main variable\
\n&nbsp;";

dleft.style.background = 'white'; dleft.style.bordercolor = 'black'; dleft.style.border = 'solid';
dleft.innerHTML = String.fromCharCode(9604) + dleft.innerHTML;

dmid.style.background = 'white'; dmid.style.bordercolor = 'black'; dmid.style.border = 'solid';

function outd(p) {
    dtop.innerHTML += "<span style='color: orange;'>" + p + "</span><br>\n";
    }

function getcursor() {
    var prompt = String.fromCharCode(9604);
    var cpos = 0;
    var lpos = 0;
    p = dleft.value.split("\n");
    for(count = 1; count < p.length + 1; count++) {
        pos = p[count - 1];
        if (pos.indexOf(prompt) > -1) {
            lpos = count;
            cpos = pos.indexOf(prompt) + 1
            break;
            }
        }
    return (cpos + " " + lpos).split(" ");
    }

function cursorup() {
    var p = getcursor();
    setcursor(parseInt(p[0]), parseInt(p[1]) - 1, "");
    }

function cursordown() {
    var p = getcursor();
    setcursor(parseInt(p[0]), parseInt(p[1]) + 1, "");
    }

function cursorleft() {
    var p = getcursor();
    if (parseInt(p[0]) > 1 || parseInt(p[1]) > 1) {
        setcursor(parseInt(p[0]) - 1, parseInt(p[1]), "");
        }
    }

function cursorright() {
    var p = getcursor();
    setcursor(parseInt(p[0]) + 1, parseInt(p[1]), "_right");
    }

function backkey() {
    var p = getcursor();
    if (parseInt(p[0]) > 1 || parseInt(p[1]) > 1) {
        cursorleft();
        delkey();
        }
    }

function delkey() {
    var p = getcursor();
    setcursor(parseInt(p[0]), parseInt(p[1]), "_del");
    }

function enterkey() {
    var p = getcursor();
    setcursor(parseInt(p[0]), parseInt(p[1]), "_enter");
    }

function cursorskup() {
    var plen = 0;
    for(pcount = 1; pcount < dleft.value.split("\n").length + 1; pcount++) {
        var p = getcursor(); 
        plen = setcursor(parseInt(p[0]), parseInt(p[1]) - 1, "");
        if (plen == 0) {
            break;
            }
        }
    }

function cursorskdown() {
    var plen = 0;
    for(pcount = 1; pcount < dleft.value.split("\n").length + 1; pcount++) {
        var p = getcursor(); 
        plen = setcursor(parseInt(p[0]), parseInt(p[1]) + 1, "");
        if (plen == 0) {
            break;
            }
        }
    }

function cursorskleft() {
    var p = getcursor();
    var getprompt = String.fromCharCode(9604);
    var c = dleft.value.split(getprompt).join("").split("\n");
    linep = c[p[1] - 1];
    if (parseInt(p[0]) == 1) {
        cursorleft();
        return 0;
        }
    nextc = q_mid(linep, parseInt(p[0]) - 1, 1);
    if (nextc == " ") { // look for character
        nextc = q_mid(linep, 1, parseInt(p[0]) - 1);
        if (nextc.trim().length == 0) { // leading space
            setcursor(1, parseInt(p[1]), ""); 
            }
        else {
            nextc = nextc.lastIndexOf(nextc.trim()[nextc.trim().length - 1]) + 1;
            setcursor(nextc + 1, parseInt(p[1]), ""); 
            }
        }
    else { // look for space then character
        nextc = q_mid(linep, 1, parseInt(p[0]) - 1);
        nextc = nextc.lastIndexOf(" ") + 1;
        if (nextc == 0) { // trailing character
            setcursor(1, parseInt(p[1]), "");
            }
        else {
            setcursor(nextc + 1, parseInt(p[1]), ""); 
            }
        }
    }

function cursorskright() {
    var p = getcursor();
    var getprompt = String.fromCharCode(9604);
    var c = dleft.value.split(getprompt).join("").split("\n");
    linep = c[p[1] - 1];
    if (p[0] > linep.length) {
        setcursor(parseInt(p[0]) + 1, parseInt(p[1]), "_right");
        return 0;
        }

    nextc = q_mid(linep, p[0], 1);

    if (nextc == " ") { // look for character
        if (nextc.trim().length > 0) { // trailing space
            setcursor(linep.length, parseInt(p[1]), "_right"); 
            }
        else {
            nextc = q_mid(linep, parseInt(p[0]), linep.length);
            nextc = nextc.indexOf(nextc.trim()[0]) + 1;
            setcursor(parseInt(p[0]) + nextc -1, parseInt(p[1]), "_right"); 
            }
        }
    else { // look for space then character
        nextc = q_mid(linep, parseInt(p[0]), linep.length);
        nextc = nextc.indexOf(" ") + 1;
        if (nextc == 0) { // trailing character
            setcursor(linep.length + 1, parseInt(p[1]), "_right");
            }
        else {
            setcursor(parseInt(p[0]) + nextc, parseInt(p[1]), "_right"); 
            }
        }
    }

function cursorletter(c) {
    var p = getcursor();
    setcursor(parseInt(p[0]), parseInt(p[1]), c);
    setcursor(parseInt(p[0]) + 1, parseInt(p[1]), "");
    }

function setcursor(cpos, lpos, c) {
    var d = "";
    var poslen = 0;
    if (c == "_enter") { d = c; c = "\n"; }
    if (c == "_bksp") { d = c; c = ""; }
    if (c == "_del") { d = c; c = ""; }
    if (c == "_line") { d = c; c = ""; }
    if (c == "_token") { d = c; c = ""; }
    if (c == "_right") { d = c; c = ""; }
    var getprompt = String.fromCharCode(9604);
    if (d == "_enter") {
        var prompt = String.fromCharCode(9604) + c;
        }
    else {
        var prompt = String.fromCharCode(9604) + c;
        }
    var buf = "";
    var dflag = 0; // 1 = dont join lines when rightmost character is deleted
    var rflag = 0; // 1 = seek rightmost character
    p = dleft.value.split(getprompt).join("").split("\n");
    if (cpos < 1) { lpos -= 1; rflag = 1; }
    if (lpos < 1) { lpos = 1; }
    if (lpos > p.length) { lpos = p.length; }
    for(count = 1; count < p.length + 1; count++) {
        pos = p[count - 1];
        if (count == lpos) {
            poslen = pos.trim().length;
            if (cpos > pos.length || rflag == 1) { 
                if (rflag == 1 || lpos >= p.length || d != "_right") {
                    pos += prompt; 
                    }
                else {
                    if (cpos > pos.length + 1 && d == "_right") { 
                        setcursor(1, lpos +1, ""); return 0;
                        }
                    else { 
                        setcursor(cpos, lpos, ""); return 0;
                        }

                    }
                }
            else {
                if (d == "_del") { 
                    pos = pos.substring(0, cpos -1) + prompt + pos.substring(cpos, pos.length);
                    dflag = 1;
                    }
                else {
                    pos = pos.substring(0, cpos -1) + prompt + pos.substring(cpos - 1, pos.length);
                    }
                }
            }
        buf += pos;
        if (count < p.length && (count != lpos || cpos < pos.length || d != "_del" || dflag == 1)) {
            buf += "\n";
            }
        }
    dleft.innerHTML=buf;
    if (d == "_enter") {
        setcursor(1, lpos + 1, "");
        }
    return poslen;
    }

function left(s, l) {
    return s.substring(0, l);
    }

function right(s, l) {
    return s.substring(s.length-l, s.length);
    }

var addfuncs = "\n\
var cgasel = -1;\n\
var buc = -1;\n\
var cgapal = \"0,0,0=0,0,170=0,170,0=0,170,170=\
170,0,0=170,0,170=170,85,0=170,170,170=\
85,85,85=85,85,255=85,255,85=85,255,255=\
255,85,85=255,85,255=255,255,85=255,255,255\";\n\
function q_cls(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    dtop.innerHTML = \"\";\n\
    }\n\
\n\
function q_date(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    d = Date().toLocaleString().split(\" \");\n\
    months = {\n\
        'Jan': '01',\n\
        'Feb': '02',\n\
        'Mar': '03',\n\
        'Apr': '04',\n\
        'May': '05',\n\
        'Jun': '06',\n\
        'Jul': '07',\n\
        'Aug': '08',\n\
        'Sep': '09',\n\
        'Oct': '10',\n\
        'Nov': '11',\n\
        'Dec': '12',\n\
        }\n\
    return (months[d[1]] + \"/\" + d[2] + \"/\" + d[3] + \"_\" + d[4] + \"_\" + d[0]).split(\"_\");\n\
    }\n\
\n\
function q_end(p) {\n\
    progrun.innerHTML = \"<!-- -->\";\n\
    }\n\
\n\
function q_len(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return p.length;\n\
    }\n\
\n\
function q_print(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    dtop.innerHTML = dtop.innerHTML\
    + \"</span><span style='color: rgb(\" + q_str(cgapal.split('=')[cgasel])+\");'>\" + p + \"</span><br>\\n\";\n\
    }\n\
\n\
function q_color(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    cgasel = s;\n\
    }\n\
\n\
function q_colour(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    cgasel = s;\n\
    }\n\
\n\
function q_chr(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return String.fromCharCode(p);\n\
    }\n\
\n\
function q_asc(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return String.charCodeAt(p[0]);\n\
    }\n\
\n\
function q_prints(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    dtop.innerHTML = dtop.innerHTML\
    + \"</span><span style='color: rgb(\" + q_str(cgapal.split('=')[cgasel])+\");'>\" + p + \"</span>\";\n\
    }\n\
\n\
function q_str(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return \"\" + p;\n\
    }\n\
\n\
function q_title(p) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    document.title = p;\n\
    }\n\
\n\
function q_get(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return (s);\n\
    }\n\
\n\
function q_mod(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return p % s;\n\
    }\n\
\n\
function q_instr(p, s, o) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return s.indexOf(o) + 1;\n\
    }\n\
\n\
function q_left(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    if (typeof(p) == \"object\") {\n\
        var t = [];\n\
        for(count = 0; count < s; count++) {\n\
            t.push(p[count]);\n\
            }\n\
        }\n\
    else {\n\
        var t = p.substring(0, s);\n\
        }\n\
    return t;\n\
    }\n\
\n\
function q_right(p, s) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    if (typeof(p) == \"object\") {\n\
        var t = [];\n\
        for(count = p.length - s; count < p.length; count++) {\n\
            t.push(p[count]);\n\
            }\n\
        }\n\
    else {\n\
        var t = p.substring(p.length - s, p.length);\n\
        }\n\
    return t;\n\
    }\n\
\n\
function q_split(p, s, o) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return s.split(o);\n\
    }\n\
\n\
function q_join(p, s, o) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    return s.join(o);\n\
    }\n\
\n\
function q_mid(p, s, o) {\n\
    if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
    if (typeof(p) == \"object\") {\n\
        var t = [];\n\
        for(count = s - 1; count < s -1 + o; count++) {\n\
            t.push(p[count]);\n\
            }\n\
        }\n\
    else {\n\
        var t = p.substring(s - 1, s - 1 + o);\n\
        }\n\
    return t;\n\
    }\n\
\n\
";

function prefvars(parstack) {
    if (parstack.indexOf("function") > -1) {
        return "func";
        }
    else {
        return "";
        }
    }

function petcvar(p) {
    if (p != "") {
    pref = "";
    if (parstack.indexOf("function") > -1) {
        pref = "func";
        }

        if ("-01234567890".indexOf(p[0]) > -1 || p[0] == "\"") {
            return p
            }
        else {
            return pref + "vars." + p;
            }
        }
    }

eval(addfuncs); q_cls(0);

ufns = { }

cmds = {
    asc: 0,
    chr: 0,
    cls: 0,
    color: 1,
    colour: 1,
    date: 0,
    end: 0,
    for: -4,
    function: -1,
    get: 1,
    instr: 2,
    join: 2,
    left: 1,
    len: 0,
    mid: 2,
    mod: 1,
    print: 0,
    prints: 0,
    return: -1,
    right: 1,
    split: 2,
    str: 0,
    title: 0
    }

function runimport() { 
    parstack = []    
    parsed = textparse(); 
    if (parsed != "") { 
        dtop.innerHTML = "";
        eval(parsed);
        }
    }

function showcompiledimport() { 
    parstack = []    
    parsed = textparse(); 
    if (parsed != "") { 
        dtop.innerHTML = "";
        dtop.innerHTML += "<br>" + parsed.split("\n").join("<br>\n");
        }
    }

function showhelp() { 
    dtop.innerHTML = "<br><b>list of commands</b><br><br>\n";
    dtop.innerHTML += helptext.split("\n").join("<br>\n").split("[lit]*[lit]").join(String.fromCharCode(8729)).split("/").join("<i>").split("!").join("</i>");
    }

function showlicense(licenseinfo) { 
    dtop.innerHTML = licenseinfo;
    }

function textparse() { 
    vars = { }
    funcvars = { }
    funcvarset = "";
    ufns = { }
    progrun.innerHTML = "";
    var p = "";
    var prompt = String.fromCharCode(9604);
    var cmdcount = 0;
    var petc = "";
    var getcmd = "";
    var getvar = "";
    var cc = dleft.value.split(prompt).join("") + "\n";
    var codeout = "";
    var bu = 0;
    var funcbu = 0;
    var inquotes = 0;
    var misquotes = 0;
    var commented = 0;
    var tokcount = 0;
    var mainvar = "";
    var mainvarplus = "";
    var prevcmd = "";
    var tokisnum = 0;
    var special = "";
    codeout += "vars = { }\n" + addfuncs;
    for(count = 0; count < cc.length; count++) {
        p = cc.substring(count, count + 1);
        if (commented == 0 && inquotes == 0) {
            if (p == "=" || p == ":" || p == ";") {
                p = " "; // allow optional ; or =
                }
            }
        if (p == "#") { 
            commented = 1; 
            }
        if (p == "\"") { 
            if (inquotes == 1) {
                inquotes = 0;
                } 
            else {
                inquotes = 1;
                }
            }
        if (p == String.fromCharCode(8221)) { 
            if (misquotes == 1) {
                p = "\"";
                inquotes = 0;
                misquotes = 0;
                }
            }
        if (p == String.fromCharCode(8220)) { 
            if (inquotes == 0) {
                p = "\"";
                inquotes = 1;
                misquotes = 1;
                }
            }
        if (commented == 0 && inquotes == 0 && left(petc, 1) != "#") {
            if (p == " " || p == "\n") {
                if (petc.trim() != "") { 
                    tokcount += 1 
                    }
                if (p == " ") { 
                    p = ""; 
                    }
                if (petc != "") {
                    tokisnum = 0;
                    getcmd = undefined; getufn = undefined;
                    if ("-01234567890".indexOf(petc[0]) > -1 || petc[0] == "\"") { 
                        tokisnum = 1; getcmd = undefined;
                        }
                    else {
                        eval("getcmd=cmds." + petc + ";");
                        eval("getufn=ufns." + petc + ";");
                        }
                    if (getcmd != undefined || getufn != undefined) {
                        if (getufn == undefined) {
                            cmdcount = getcmd;
                            mainvarplus = "";
                            getcmd = "q_" + petc + "(";
                            }
                        else {
                            cmdcount = getufn;
                            mainvarplus = "";
                            getcmd = "f_" + petc + "(";
                            }
                        prevcmd = getcmd;
                        if (tokcount > 1) { 
                            if (cmdcount == 0) {
                                var fv = ""; 
                                if (prefvars(parstack) != "func") { 
                                    fv = "funcvars = { } \n"; 
                                    }

                                codeout += prefvars(parstack) + "bu = " + mainvar + "; " + fv + mainvar + " = " + getcmd + mainvar + "); "; 
                                codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = " + prefvars(parstack) + "bu; }\n"; 
                                }
                            if (petc == "for") { special = "for"; cmdcount = -4 ; parstack.push("for"); }
                            if (petc == "return") { special = "return"; cmdcount = -1 ; }
                            if (petc == "function") { 
                                special = "function"; parstack.push("function"); funcvarset = "";

                                eval("getvar=ufns." + mainvar.split("vars.").join("") + " = 0;"); 
                                if (getvar == undefined) { eval("vars." + petc + " = 0;"); }
                                codeout += "function f_" + mainvar.split("vars.").join("") + "(q_mainvar"; 
                                cmdcount = -1 }
                            }
                        else {
                            codeout += getcmd + "); "; 
                            }
                        }
                    else {
                        if (petc != "")  {
                        try {
                            getvar = 0 ; 
                            if (tokisnum == 0) { eval("getvar=" + prefvars(parstack) + "vars." + petc + ";"); }
                            if (tokcount == 1) { 
                                if (petc == "prev" || petc == "next") {
                                    if (petc == "next") {
                                    if (parstack[parstack.length - 1] == "function") {
                                        codeout += "funcbu = 0; "; // for previous solution
                                        }
                                        codeout += " }\n";
                                        if (parstack.length > 0) {
                                            parstack = parstack.slice(0, parstack.length - 1);
                                            }
                                        } 
                                    } 
                                else {
                                     mainvar = prefvars(parstack) + "vars." + petc;
                                     codeout += "if (" + prefvars(parstack) + "vars." + petc + " == undefined) { " + prefvars(parstack) + "vars." + petc + " = 0; }\n"; 
                                     }
                                }
                            else {
                                if (cmdcount < -1 && special == "function") {
                                    codeout += ", " + petc; 
                                    funcvarset += "funcvars." + petc + " = " + petc + "; ";
                                    eval("getvar=ufns." + mainvar.split("vars.").join("") + " += 1;"); 
                                    cmdcount -= 1;
                                    }
                                if (cmdcount == -1 && special == "function") {
                                    // codeout += petc; 
                                    codeout += ", " + petc; // because f_ call expects q_mainvar parameter
                                    funcvarset += "funcvars." + petc + " = " + petc + "; ";
                                    eval("getvar=ufns." + mainvar.split("vars.").join("") + " += 1;"); 
                                    cmdcount -= 1;
                                    }

                                if (cmdcount == -1 && special == "return") {
                                    codeout += "return " + petcvar(petc) + ";";
                                    }

                                if (cmdcount == -2 && special == "for") {
                                    codeout += mainvar + "+= " + petcvar(petc) + ") {\n" 
                                    cmdcount += 1; special = "";
                                    }
                                if (cmdcount == -3 && special == "for") {
                                    codeout += mainvar + " < (" + petcvar(petc) + " + 1); "; 
                                    cmdcount += 1;
                                    }
                                if (cmdcount == -4 && special == "for") {
                                    codeout += "for(" + mainvar + " = " + petcvar(petc) + "; "; 
                                    cmdcount += 1; 
                                    }
                                if (cmdcount == 0) {
                                    var fv = ""; 
                                    if (prefvars(parstack) != "func") { 
                                        fv = "funcvars = { } \n"; 
                                        }

                                    codeout += prefvars(parstack) + "bu = " + mainvar + "; " + fv + mainvar + " = " + getcmd + mainvar + mainvarplus + "); "; 
                                    codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = " + prefvars(parstack) + "bu; }\n"; 
                                    }
                                if (cmdcount == 1) {
                                    if (tokisnum == 0) { 
                                        mainvarplus += ", " + prefvars(parstack) + "vars." + petc; cmdcount -= 1; }
                                    else {
                                        mainvarplus += ", " + petc; cmdcount -= 1;
                                        }

                                    var fv = "";  
                                    if (prefvars(parstack) != "func") { 
                                        fv = "funcvars = { } \n"; 
                                        }

                                    codeout += prefvars(parstack) + "bu = " + mainvar + "; " + mainvar + " = " + prevcmd + mainvar + mainvarplus + "); ";
                                    codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = " + prefvars(parstack) + "bu; } \n"; 

                                    }
                                if (cmdcount > 1) {
                                    if (tokisnum == 0) { 
                                        mainvarplus += ", " + prefvars(parstack) + "vars." + petc; cmdcount -= 1; }
                                    else {
                                        mainvarplus += ", " + petc; cmdcount -= 1;
                                        }
                                    }
                                }
                            }
                        catch(err) { }
                            }
                        if (getvar == undefined) { eval(prefvars(parstack) + "vars." + petc + " = 0;"); }
                        }
                    petc = "";
                    }	
                }
            }
        if (p == "\n") {
            tokcount = 0; 
            commented = 0;
            inquotes = 0;
            if (special == "function") {
                codeout += ") {\n" + funcvarset;
                }
            special = "";
            if (left(petc, 1) == "#") {
                codeout += "// " + petc + "\n\n"; 
                }
            else {
                codeout += "\n";
                }
            petc = ""; }
        else {
            if (inquotes == 0 && commented == 0) {
                petc = (petc + p).trim(); }
            else {
                petc = petc + p;
                }
            }
        }
    return codeout;
    }

dtop.innerHTML = "<br>" + document.title + "<br>Copyright (C) 2020 mn<br><br>This program is free software: you can redistribute it and/or modify it under the terms of the <a href='gpl-3.0.txt'>GNU General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br><br>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.<br><br>You should have received a copy of the GNU General Public License along with this program. If not, see <a href='https://www.gnu.org/licenses/'>https://www.gnu.org/licenses/</a>."; var licenseinfo = dtop.innerHTML;

</script>
</body>
